package www.study.com;

//移除元素 https://leetcode.cn/problems/remove-element/
public class code27 {
    public static void main(String[] args) {

    }

    class Solution {
        public int removeElement(int[] nums, int val) {
            int lef = 0; //当前遍历到的数组位置 - 可知[0,lef - 1]范围的数组是合法的
            int reg = nums.length - 1; //当前有效数组的右边界
            while(lef <= reg){
                if(nums[lef] == val){
                    swap(nums,lef,reg--);
                }else{
                    lef++;
                }
            }
            return reg + 1;
        }
        public void swap(int[] nums,int a,int b){
            int cur = nums[a];
            nums[a] = nums[b];
            nums[b] = cur;
        }
    }
}
